package com.atguigu.stgy.web.admin.controller.apartment;

import com.atguigu.stgy.common.result.Result;
import com.atguigu.stgy.model.entity.PaymentType;
import com.atguigu.stgy.web.admin.service.PaymentTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "支付类型管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {
    @Autowired
    private PaymentTypeService paymentTypeService;

    // 1.查询全部支付方式列表
    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result <List<PaymentType>> listPaymentType(){
        List<PaymentType> list = paymentTypeService.list();
        return Result.ok(list);
    }

    // 2.保存或更新支付方式
    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }

    // 3.根据ID删除支付方式
    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    /*3
        @RequestParam 注解的作用是：
        从 DELETE 请求的查询参数中提取名为 "id" 的参数
        将其转换为 Long 类型并赋值给方法参数 id
     */
    public Result deletePaymentTypeById(@RequestParam Long id) {
        paymentTypeService.removeById(id);
        return Result.ok();
    }
}
